package Persistance.KMeans;

public class ClusterCenter
{
    private static final int MAX = 18;
    private double	x[];//_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
	private Cluster	_cluster;

	public ClusterCenter(double x[])
	{
        this.x = new double[MAX];
        System.arraycopy(x, 0, this.x, 0, MAX);
    }

	public void calcCenter()
	{
		int numDP = _cluster.NumOfPoints();
        double temp[] = new double[18];
//        double temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 0, temp5 = 0, temp6 = 0, temp7 = 0
		//, temp8 = 0, temp9 = 0, temp10 = 0, temp11 = 0, temp12 = 0, temp13 = 0, temp14 = 0
		//, temp15 = 0, temp16 = 0, temp17 = 0, temp18 = 0;
		
		for (int i = 0; i < numDP; i++)
		{
            for(int j=0;j<MAX;j++){
                temp[j] += _cluster.getPoint(i).get(j);
            }
        }


        for(int j=0;j<MAX;j++){
            this.x[j] = temp[j]/numDP;
        }

//		tempX = 0;
//		tempY = 0;
		for (int i = 0; i < numDP; i++)
		{
			_cluster.getPoint(i).calcDistance();
		}		
		_cluster.calcSumOfSquares();
	}

	public void setCluster(Cluster c)
	{
		this._cluster = c;
	}

    public double get(int i){
        return this.x[i];
    }

	public Cluster getCluster()
	{
		return _cluster;
	}
}